home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 October: Technology Seed / ADC Seed CD - October 1999.toast / FireWire / FireWire_2.0_SDK / Source / SBP2 / FWSBP2DiskDriver / FWSBP2DiskDriver.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-04-12  |  6.9 KB  |  210 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        FWSBP2DiskDriver.h
  3.  
  4.     Contains:    Include file for sample SBP-2 disk driver
  5.  
  6.     Version:    1.0
  7.  
  8.     Copyright:    © 1998-1999 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     File Ownership:
  11.  
  12.         DRI:                Clinton Bauder
  13.  
  14.         Other Contact:        Eric Anderson
  15.  
  16.         Technology:            FireWire
  17.  
  18.     Writers:
  19.  
  20.         (EA)    Eric Anderson (ewa)
  21.         (DCB)    Clinton Bauder
  22.  
  23.     Change History (most recent first):
  24.  
  25.       <FW17>      3/8/99    DCB        Get rid of unused variables, cleanup our login state variables
  26.                                     and add some constants for payload size and error recovery
  27.                                     control.
  28.       <FW16>      3/4/99    DCB        Support for write verification.
  29.       <FW15>      3/2/99    DCB        Put drive info in DrvSts2. Less of a hack this way, kinda sorta
  30.                                     (the whole structure is a hack but at least its not MY hack.)
  31.       <FW14>     2/22/99    EA        Removed registrationRef; nobody was using it.
  32.       <FW13>     2/16/99    DCB        Add better support for 2 macs-1 drive, that is do the right
  33.                                     thing if we fail a login.
  34.       <FW12>     2/15/99    DCB        Cleanup for Eric's notification changes.
  35.       <FW11>     1/25/99    DCB        Even yet more re-plug stuff.
  36.       <FW10>     1/21/99    DCB        Even more stuff for hot-plugging.
  37.        <FW9>     1/19/99    DCB        More stuff for unplugging/repluggin.
  38.        <FW8>     1/15/99    DCB        Stuff for unplugging drives.
  39.        <FW7>    12/29/98    DCB        Added a buffer for double buffering. Could get quite large if
  40.                                     kMaxTransfer size is large enough.
  41.        <FW6>    12/23/98    DCB        Don't do ReqSense anymore as some drives don't like this. Back
  42.                                     to straight retries for error checking. Also fixed up the
  43.                                     Symbios ROM flash code.
  44.        <FW5>    12/18/98    DCB        Change use of login var.
  45.        <FW4>    12/18/98    DCB        Fixed Comment header. Time to go home...
  46.        <FW3>    12/18/98    DCB        A few changes for clear box support.
  47.        <FW2>    11/17/98    DCB        Misc Cleanup.
  48.        <FW1>    11/17/98    DCB        first checked in
  49.        <FW2>     9/20/98    EA        Filled in header comments.
  50.        <FW1>     9/20/98    EA        first checked in
  51. */
  52.  
  53.  
  54. #ifndef __FWSBP2DRIVER__
  55. #define __FWSBP2DRIVER__
  56.  
  57. #ifndef __TYPES__
  58. #include <Types.h>
  59. #endif
  60. #ifndef __FIREWIRE__
  61. #include <FireWire.h>
  62. #endif
  63.  
  64. #ifdef __cplusplus
  65. extern "C" {
  66. #endif
  67.  
  68. #if PRAGMA_IMPORT_SUPPORTED
  69. #pragma import on
  70. #endif
  71.  
  72. #if PRAGMA_ALIGN_SUPPORTED
  73. #pragma options align=mac68k
  74. #endif
  75.  
  76. // Turn this on to read back all writes to compare the data. Uses about 125K of RAM for a max transfer of 250 blocks
  77. #define VerifyWrites 0
  78.  
  79. // Turn this on if your device doesn't handle fetch agent resets properly
  80. #define needLUNReset 1
  81.  
  82. enum {
  83.  
  84.     kBlockSize = 512,
  85.     kMaxTransfer = 250,                // Set to 1 for clear box drive
  86.     
  87.     kDiskDriverPayloadSize = 256,     // Packet size. 256 for safety on Blue and White G3s.
  88.                                     // For devices that recover gracefully from an occasional
  89.                                     // short packet this could be increased to 512 or even 1024
  90.     
  91.     kAsyncORB = 0,
  92.     kImmedORB = 2,
  93.     kTotalORBs = 3
  94.     
  95. };
  96.  
  97. struct FWSBP2DriverDataStruct
  98. {
  99.     // Important! Next two items need to be at the front of this structure in order to be aligned properly!
  100.     
  101.     UInt8                        dataBuffer[kMaxTransfer << 9];        // For double buffering. !!! Could get real big!
  102.  
  103. #if VerifyWrites
  104.     UInt8                        verifyBuffer[kMaxTransfer << 9];    // For double buffering. !!! Could get real big!
  105.     UInt8                        * whatWasWritten;
  106. #endif
  107.  
  108.     FWDriverID                    fwDriverID;                // Our driver ID.
  109.     CSRROMEntryID                csrUnitID;                // Out unit directory ID.
  110.     RegEntryID                    pRegEntryID;
  111.     
  112.     SInt16                        drvrRefNum;
  113.     Boolean                        gotEject;                // True if we got ejected/offlined at some point...
  114.     Boolean                        returnDiskErr;            // True if user canceled the replug dialog
  115.  
  116.     FWCommandObjectID            loginCommandID;            // Login command object
  117.  
  118.     Boolean                        loggedIn;                // True if we are logged in
  119.     Boolean                        wasLoggedIn;            // true if at some point we successfully logged into the drive.
  120.     Boolean                        doubleBuffer;            // True if we are double buffering this transfer.
  121.     Boolean                        wait4Replug;            // True if we're waiting for a re-plug.
  122.                                                         // Don't bother with reset notification or other nonsense
  123.                                                         // until FSL thinks we're back.
  124.                                                         
  125.     volatile Boolean            loginObjBusy;            // True if login ORB object
  126.     Boolean                     reLogin;                // True if after a logout we want to try and login again
  127.     Boolean                        unused[2];                // Pad to longword
  128.     
  129.     SInt32                         lookForDriveReqs;        // Number of times an event occured triggering a "look for disk" request
  130.     SInt32                         loginReqs;                // Number of times an event occured triggering a login request
  131.  
  132.     FWAddress                    fetchAgent;                // From login response.
  133.  
  134.     FWCommandObjectID            orbID[4];                // ORB command objects 2 for Async, 1 for Immediate, 1 for other stuff
  135.     UInt32                        currentORB;                // 1 or 0 depending on which one we're using
  136.     FWCommandObjectID            fwAGENT_RESET_ID;        // Command object for FWWrite
  137.     FWCommandObjectID            fwLUNReset_ID;            // Command object for resetting LUN with kSBP2LogicalUnitReset
  138.     FWCommandObjectID            fwReconnectID;            // Command object for reconnecting after device goes away
  139.     FWCommandObjectID            fwReplugID;                // Command object for requesting a drive re-plug
  140.     
  141.     volatile OSStatus            immedStatus;            // Status of immediate command                            
  142.     volatile OSStatus            utilStatus;                // Status of utility command                            
  143.     
  144.     UInt32                        xferLeft;                // Used for really BIG transfers that can't
  145.                                                         // be completed with 1 10 byte command
  146.     UInt32                        next_block;                // next block to xfer to 
  147.     Ptr                            next_buffer;            // next chunk of buffer
  148.     
  149.     Boolean                        ioPending;                // Used for error handling
  150.     Boolean                        isWrite;                // Used for retries and big commands
  151.     Boolean                        queuedDQEl;                // True if we called AddDrive.
  152.     Boolean                        needsVerify;
  153.     UInt32                        retriesLeft;            // ""
  154.     UInt32                        count;                    // ""
  155.     UInt32                        sector;                    // ""
  156.     Ptr                            buffer;                    // ""
  157.     
  158.     FWAddress                    buffers[1];                // ""
  159.     UInt32                        lengths[1];                // ""
  160.     UInt8                        command[12];            // ""
  161.     UInt8                        aBuffer[12];            // Used for ReqSense
  162.     
  163.     IOParamPtr                     ioPB;                    // Remember the current parameter block and dce for
  164.     DCtlEntry                    * dce;                    // the benefit of the async callback routine
  165.     IOCommandID                    ioCommandID;            // Remember command ID as well
  166.     
  167.     UInt32                        totalBlocks;            // Size of the disk in blocks
  168.  
  169.     UInt32                        bitBucket;                // place to throw away data.                
  170.  
  171.     // DrvSts2 is a particularly gross legacy structure. Using it is probably cleaner than trying
  172.     // to duplicate the structure inside of our own globals although it introduces other inconveniences
  173.     // when trying to use some of the fields within.
  174.     DrvSts2                        driveStatus;
  175.         
  176. };
  177. typedef struct FWSBP2DriverDataStruct
  178.                                 FWSBP2DriverData,
  179.                                 *FWSBP2DriverDataPtr;
  180.                                 
  181. struct sbpStatusBlockStruct
  182. {
  183.     UInt8                        stSrcRespLen;
  184.     UInt8                        stSBPStatus;
  185.     UInt16                        stOrbOffsetHi;
  186.     UInt32                        stOrbOffsetLo;
  187.     UInt8                        stStatus;
  188.     UInt8                        stKey;
  189.     UInt8                        stCode;
  190.     UInt8                        stQualifier;
  191. };
  192. typedef struct sbpStatusBlockStruct
  193.                                 sbpStatusBlock,
  194.                                 *sbpStatusBlockPtr;
  195.  
  196.  
  197. #if PRAGMA_ALIGN_SUPPORTED
  198. #pragma options align=reset
  199. #endif
  200.  
  201. #if PRAGMA_IMPORT_SUPPORTED
  202. #pragma import off
  203. #endif
  204.  
  205. #ifdef __cplusplus
  206. }
  207. #endif
  208.  
  209. #endif /* __FWSBP2DRIVER__ */
  210.